<template>
    <cl-crud ref="Crud">
        <cl-row>
            <!-- 刷新按钮 -->
            <cl-refresh-btn />
            <!-- 新增按钮 -->
            <!-- <cl-add-btn /> -->
            <!-- 删除按钮 -->
            <cl-multi-delete-btn />
            <cl-flex1 />
            <!-- 关键字搜索 -->
            <cl-search-key placeholder="搜索用户id" />
        </cl-row>

        <cl-row>
            <!-- 数据表格 -->
            <cl-table ref="Table" />
        </cl-row>

        <cl-row>
            <cl-flex1 />
            <!-- 分页控件 -->
            <cl-pagination />
        </cl-row>

        <!-- 新增、编辑 -->
        <cl-upsert ref="Upsert" />
    </cl-crud>
</template>

<script lang="ts" name="user-setting" setup>
import { useCrud, useTable, useUpsert } from "@cool-vue/crud";
import { useCool } from "/@/cool";
import { reactive } from "vue";

const { service } = useCool();
const options = reactive({
	playMode: [
		{
			label: "指定音频",
			value: 0
		},
		{
			label: "随机播放",
			value: 1
		}
	]
});
// cl-upsert
const Upsert = useUpsert({
	items: [
		{
			label: "用户ID",
			prop: "userId",
			component: { name: "el-input", props: { clearable: true } },
			required: true
		},
		{
			label: "播放方式",
			prop: "playMode",
			component: { name: "el-radio-group", options: [] }
		},
		{
			label: "音量",
			prop: "volume",
			hook: "number",
			value: 0.7,
			component: { name: "el-input-number", props: { step: 0.1 } }
		},
		{
			label: "音频ID",
			prop: "audioId",

			component: { name: "el-input", props: { clearable: true } },
			required: true
		}
	]
});

// cl-table
const Table = useTable({
	columns: [
		{ type: "selection" },
		{ label: "用户ID", prop: "userId", minWidth: 140 },
		{ label: "用户昵称", prop: "nickName", minWidth: 140 },
		{
			label: "播放方式",
			prop: "playMode",
			dict: options.playMode,
			dictColor: true,
			minWidth: 120
		},
		{ label: "音量", prop: "volume", minWidth: 140 },
		{ label: "音频ID", prop: "audioId", minWidth: 140 },
		{
			label: "创建时间",
			prop: "createTime",
			minWidth: 170,
			sortable: "custom",
			component: { name: "cl-date-text" }
		},
		{
			label: "更新时间",
			prop: "updateTime",
			minWidth: 170,
			sortable: "custom",
			component: { name: "cl-date-text" }
		},
		{ type: "op", buttons: ["delete"] } //"edit",
	]
});

// cl-crud
const Crud = useCrud(
	{
		service: service.user.setting
	},
	(app) => {
		app.refresh();
	}
);
</script>
